import { Navigate } from "react-router";

import DashboardLayout from "@/layouts/dashboard";

import AuthGuard from "../components/auth-guard";
import { getRoutesFromModules } from "../utils";

import type { AppRouteObject } from "#/router";

import components from "./modules/components";
import dashboard from "./modules/dashboard";
import functions from "./modules/functions";
import management from "./modules/management";
import notifications from "./modules/notifications";
import projects from "./modules/projects";
import task from "./modules/task";

const menuModuleRoutes = getRoutesFromModules();

const { VITE_APP_HOMEPAGE: HOMEPAGE } = import.meta.env;

/**
 * dynamic routes
 */
export const menuRoutes: AppRouteObject = {
	path: "/",
	element: (
		<AuthGuard>
			<DashboardLayout />
		</AuthGuard>
	),
	children: [
		{ index: true, element: <Navigate to={HOMEPAGE} replace /> },
		...menuModuleRoutes,
		...[dashboard, management, task, components, functions, projects, notifications],
	],
};
